package scut.kent.shopping.util;
import org.apache.commons.beanutils.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {
	
	public static Object getObject(Class<?> cla,HttpServletRequest req){
System.out.println("\n\n\n\n\n\nthis is requestUtil");
		Object obj=null;
		Set<String> keyset = req.getParameterMap().keySet();
		try {
			obj=cla.newInstance();
			for(String key:keyset){
				String value = req.getParameter(key);
				BeanUtils.copyProperty(obj, key, value);
				System.out.println(key+":"+value);
			}
			
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
System.out.println("\n\n\n\n\n\nthis is requestUtil");
		return obj;
	}
}
